package com.intellij.licensecommon.net;

import com.intellij.licensecommon.message.Message;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class j extends Thread {
    private volatile boolean a = false;
    private final BlockingQueue<a_> b = new LinkedBlockingQueue();

    public j() {
        super("MessageDeliveryThread");
    }

    public void run() {
        int i = 1;
        while (i != 0) {
            try {
                a_ locala_ = (a_) this.b.take();
                i = (locala_ != a_.a) && (!this.a) ? 1 : 0;
                if (i != 0) {
                    locala_.a();
                }
            } catch (InterruptedException localInterruptedException) {
                localInterruptedException.printStackTrace();
                i = 0;
            }
        }
        this.b.clear();
    }

    public void a(NetworkTarget paramNetworkTarget, Message paramMessage, Address paramAddress) {
        if (!this.a) {
            this.b.offer(new a_(paramNetworkTarget, paramMessage, paramAddress));
        }
    }

    public void a() {
        this.a = true;
        this.b.offer(a_.a);
    }

    private static class a_ {
        static final a_ a = new a_(null, null, null) {
            protected void a() {
            }
        };
        final Message b;
        final Address c;
        final NetworkTarget d;

        a_(NetworkTarget paramNetworkTarget, Message paramMessage, Address paramAddress) {
            this.d = paramNetworkTarget;
            this.b = paramMessage;
            this.c = paramAddress;
        }

        protected void a() {
            try {
                this.d.a(this.b, this.c);
            } catch (Throwable localThrowable) {
                this.d.b(localThrowable);
            }
        }
    }
}
